package com.EAIPClub.codeidemanager.mapper;

import com.api.POJO.CodeLab.CodeIdeManager.CodeIdeAccount;
import com.api.POJO.CodeLab.CodeIdeManager.CodeIdeUserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description :CodeIde管理模块Mapper
 * @Author :崔昌赫
 * @Date : 2021/10/26
 */
@Repository
@Mapper
public interface CodeIdeManagerMapper {
    @Insert("INSERT INTO user_codeidepassword VALUES ('${account.uid}','${account.password}')")
    Boolean addNewCodeIdePassword(@Param("account") CodeIdeAccount account);


    @Insert("INSERT INTO user_location VALUES ('${info.uid}','${info.location}','${info.containerId}','${info.node}','${info.port}')")
    Boolean addNewCodeIdeUserInfo(@Param("info")CodeIdeUserInfo info);

    @Select("SELECT * FROM user_codeidepassword WHERE uid='${uid}'")
    CodeIdeAccount findCodeIdePasswordByUid(@Param("uid") String uid);
    @Select("SELECT * FROM user_location WHERE uid='${uid}'")
    CodeIdeUserInfo findCodeIdeUserInfoByUid(@Param("uid") String uid);

    @Select("SELECT nodeip FROM node_ip WHERE node = '${node}'")
    String getNodeIp(@Param("node") String node);

    @Select("SELECT port FROM user_location WHERE 1=1")
    List<String> getAllPorts();
}
